<?php
/**
*
* @author kmklr72 (Kevin Murek) kmklr72@charter.net 
* @package umil
* @copyright (c) 2009 kmklr72 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/chat_mod_install');

if (!file_exists($phpbb_root_path . 'umil/umil.' . $phpEx))
{
	trigger_error('Please download the latest UMIL (Unified MOD Install Library) from: <a href="http://www.phpbb.com/mods/umil/">phpBB.com/mods/umil</a>', E_USER_ERROR);
}

// We only allow a founder to install this MOD
if ($user->data['user_type'] != USER_FOUNDER)
{
	if ($user->data['user_id'] == ANONYMOUS)
	{
		login_box('', 'LOGIN');
	}

	trigger_error('NOT_AUTHORISED');
}

if (!class_exists('umil'))
{
	include($phpbb_root_path . 'umil/umil.' . $phpEx);
}

$umil = new umil(true);

$mod = array(
	'name'		=> 'Demon Chat',
	'version'	=> '0.0.1',
	'config'	=> 'chat_version',
	'enable'	=> 'chat_enable',
);

if (confirm_box(true))
{
	include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
	$auth_admin = new auth_admin();

	$auth_admin->acl_add_option(array(
		'local'     => array(),
		'global'    => array('u_chat_mod', 'u_chat_ban'),
	));

	$umil->config_remove('chat_enable');
	$umil->config_remove('chat_version');

	$umil->module_remove('acp', 0, 'ACP_CAT_CHAT_MOD', false);

	$umil->table_add('phpbb_chat_config', array(
		'COLUMNS'	=> array(
			'config_name'		=> array('VCHAR', ''),
			'config_value'		=> array('MTEXT', ''),
		),
		'PRIMARY_KEY'	=> 'config_name',
	));

	$umil->table_remove('phpbb_chat_config');
	$umil->table_remove('phpbb_chat');
	$umil->table_remove('phpbb_chat_channels');
	$umil->table_remove('phpbb_chat_sessions');

	$umil->table_column_remove('phpbb_users', 'user_chat_banned');

	// Our final action, we purge the board cache
	$umil->cache_purge();

	// We are done
	trigger_error('DONE');
}
else
{
	confirm_box(false, 'UNINSTALL_CHAT_MOD');
}

// Shouldn't get here.
redirect($phpbb_root_path . $user->page['page_name']);

?>